import React, { Component } from 'react';
import {  Menu } from 'antd';
import { UserOutlined, LaptopOutlined, NotificationOutlined } from '@ant-design/icons';
import getMenuView,{getOpenKey} from '@/router/router.util';
import {connect} from 'dva';
import {withRouter} from 'dva/router';
const { SubMenu } = Menu;

@connect(
    state => {
        return state
    }
)
@withRouter
class MenuList extends Component {
    //切换视图
    changeView = ({key})=>{
        this.props.history.push(key)
    }
    
    render() {
        let menuList = getMenuView(this.props.user.userViewsData);
        console.log("=======",this.props);

        let pathname = this.props.location.pathname;

        return (
            <Menu
                theme="dark"
                mode="inline"
                defaultSelectedKeys={[pathname]}
                defaultOpenKeys={getOpenKey(pathname)}
                style={{ height: '100%', borderRight: 0 }}
                onClick={this.changeView}
                >
                {menuList.map(item => <SubMenu key={item.groupId} title={item.groupName}>
                    {
                        item.children.map(val => <Menu.Item key={val.path}>{val.title}</Menu.Item>)
                    }
                </SubMenu>)}
            </Menu>
        )
    }
}

export default MenuList
